// Pinger Program for PCMod (SERVER)

PROG.PName = "Pinger"
PROG.Author = "[GU]|ZLC|thomasfn"

function PROG:Initialize( pl )
	SendClientProgram( pl, "Pinger" )
	SendClientWindow( pl, "Main" )
	
	OpenPort( pl, 72 )
	
	self:PC_Changed( pl )
end

function PROG:Unload()
	
end

function PROG:Think()

end

function PROG:CommandRecieved( ply, command, args )
	if (command == "ping") then
		result = ComposePacket( ply, args[1], 50, { "ping" } )
		ltext = "Response: " .. DeliveryStatus( result )
		BeamData_String( ply, "labelinfo_a", ltext )
	end
	if (command == "whois") then
		result = ComposePacket( ply, args[1], 73, { "whois" } )
	end
	if (command == "quit") then
		UnloadProgram( ply )
	end
end

function PROG:PC_Changed( ply )
	pc = ply.CurrentPC
	if (!pc) then return end
	PData[pc:EntIndex()].LPlayer = ply
end

function PROG:PacketRecieved( packet, pc )
	if (!pc) then return end
	ply = PData[pc:EntIndex()].LPlayer
	if (packet[4][1] == "whois_response") then
		local ltext = "Response: " .. packet[4][2]
		BeamData_String( ply, "labelinfo_b", ltext )
	end
end